<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        .center{
            width: 1200px;
            margin: 0 auto;
        }
        .scale{
            text-decoration: none;
            color: #666;
        }
        .scale:hover {
            transform: scale(1.2);
            transition-duration: .3s;
        }
        .scale:active{
            color: orange;
        }
        .el-main{
            background-image: url("imgs/denglubg.gif");
            background-size: cover;
            height: 500px;
            background-position: center;
        }
        h3{color: white}
    </style>
</head>
<body>
<div id="app">
    <common-header></common-header>

    <el-main >
            <el-card style="width: 500px; height: 300px;margin: 50px auto">
                <el-form label-width="60px" style="width: 400px;margin: 50px auto">
                    <el-form-item label="用户名">
                        <el-input type="text" v-model="user.userName" placeholder="请输入用户名"></el-input>
                    </el-form-item>
                    <el-form-item label="密码">
                        <!--@keydown.native.enter添加按下本地回车键的事件-->
                        <el-input type="password" @keydown.native.enter="login()" v-model="user.password" placeholder="请输入密码"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button style="position: relative;left: -30px" type="primary" @click="login()">登录</el-button>
                    </el-form-item>
                </el-form>
            </el-card>
    </el-main>
    <common-footer></common-footer>
</div>
</body>
<!--引入axios和vue框架文件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>

<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script src="js/common.js"></script>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                user:{userName:"",password:""}
            }
        },
        methods: {
            login(){
              axios.post("/api/user/login",v.user).then(function (response) {
                  if (response.data.code==20000){
                        console.log(response.data.data);
                      localStorage.localUser = JSON.stringify(response.data.data);
                      location.href="/";
                  }else{
                      v.$message.error(response.data.msg);
                  }
              }).catch(function (error) {
                  console.log(error);
              });




            },
            hdNavHandleSelect(key, keyPath) {

            },

        }
    })
</script>
</html>